package com.yp.lession79.esqf2111.services.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yp.lession79.esqf2111.dao.DeptMapper;
import com.yp.lession79.esqf2111.dao.EmpMapper;
import com.yp.lession79.esqf2111.entity.Dept;
import com.yp.lession79.esqf2111.entity.Emp;
import com.yp.lession79.esqf2111.entity.vo.EmpVo;
import com.yp.lession79.esqf2111.services.EmpServices;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class EmpServiecsImpl extends ServiceImpl<EmpMapper, Emp> implements EmpServices {
    @Resource
    private EmpMapper empMapper;
    @Resource
    private DeptMapper deptMapper;

    @Override  //连表查询两种选择 1.emp.xml 2.mybatis-plus
    // mybatis-plus 方式
    public List<EmpVo> getEmpVoList() {
        //1拿到所有emp的数据
        List<Emp> emps = empMapper.selectList(null);
        //创建
        List<EmpVo> empVosList = new ArrayList<>();
        for (Emp emp : emps) {
            //部门编号  通过部门编号进行连表查询
            Dept dept = deptMapper.selectById(emp.getDno());
            //把数据添加到EmpVo对象
            EmpVo empVo = new EmpVo(emp.getEno(),emp.getEname(),emp.getEsex(),
                    emp.getSalary(),emp.getBorndate(),dept.getDname());

                empVosList.add(empVo);
            
        }

        return null;
    }
}
